package com.jumi.microservice.controller;


import cn.hutool.core.util.ObjectUtil;
import com.jumi.microservice.dto.reponse.JmJpushUserResponse;
import com.jumi.microservice.entity.JmJpushUser;
import com.jumi.microservice.entity.JmUser;
import com.jumi.microservice.service.IJmJpushUserService;
import com.jumi.microservice.service.IJmUserService;
import com.jumi.microservice.service.JmJpushUserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 移动端登录令牌表 前端控制器
 * </p>
 *
 * @author 要挑客户管理团队
 * @since 2020-10-26
 */
@DubboService
@RestController
public class JmJpushUserController implements JmJpushUserService {

    @Resource
    IJmJpushUserService jmJpushUserService;

    @Resource
    IJmUserService userService;

    @Override
    public List<JmJpushUserResponse> getJgPushByUid(Integer uid) {
        List<JmJpushUser> list = jmJpushUserService.getJgPushByUid(uid);
        // 查询用户当前的手机号,而不是登录时的手机号与已返回(有可能用户在登录后修改手机号)
        JmUser user=userService.getById(uid);
        if(ObjectUtil.isNotEmpty(list)){
            List<JmJpushUserResponse> responseList=new ArrayList<>();
            for(JmJpushUser obj:list){
                obj.setMobile(user.getMobile());
                JmJpushUserResponse response=new JmJpushUserResponse();
                BeanUtils.copyProperties(obj,response);
                responseList.add(response);
            }
            return responseList;
        }
        return null;
    }
}
